//
//  JiaZaiAnimationHandle.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/5/17.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "JiaZaiAnimationHandle.h"

@interface JiaZaiAnimationHandle ()

@property (nonatomic, strong) UIImageView *animationImageV; // 动画

@end

@implementation JiaZaiAnimationHandle

+ (JiaZaiAnimationHandle *)shareJiaZaiAnimationHandle
{
    static JiaZaiAnimationHandle *jiaZaiHandle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        jiaZaiHandle = [[JiaZaiAnimationHandle alloc] init];
    });
    return jiaZaiHandle;
}

// 开始动画
- (void)startAnimation
{
    UIWindow *win = [UIApplication sharedApplication].keyWindow;
    self.animationImageV = [[UIImageView alloc] initWithFrame:CGRectMake((375 - 50) / 2 * kAdjustParamater, 300 * kAdjustParamater, 50 * kAdjustParamater, 50 * kAdjustParamater)];
    self.animationImageV.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"加载60x60-01"], [UIImage imageNamed:@"加载60x60-02"], [UIImage imageNamed:@"加载60x60-03"], [UIImage imageNamed:@"加载60x60-04"], [UIImage imageNamed:@"加载60x60-05"], [UIImage imageNamed:@"加载60x60-06"], [UIImage imageNamed:@"加载60x60-07"], [UIImage imageNamed:@"加载60x60-08"], nil];
    self.animationImageV.animationRepeatCount = 0;
    self.animationImageV.animationDuration = 1.5;
    [win addSubview:_animationImageV];
    [self.animationImageV startAnimating];
    
}

// 结束动画
- (void)stopAnimation
{
    [self.animationImageV stopAnimating];
    [self.animationImageV removeFromSuperview];
}

// 添加提醒框
- (void)addAlertTitle:(NSString *)title Content:(NSString *)content ToView:(UIViewController *)viewVC
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleAlert];
    // 修改标题颜色
    NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:@"警告"];
    [titleString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
    [titleString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
    [alertVC setValue:titleString forKey:@"attributedTitle"];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:sureAction];
    [viewVC presentViewController:alertVC animated:YES completion:nil];
    
    // 默认3秒以后消失
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [viewVC dismissViewControllerAnimated:YES completion:nil];
    });
}

// 取消提醒框
- (void)hideAlert
{
    
}

@end
